{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">

                        <div class="layui-col-md6 layui-input-inline" style="margin-top: 5px">
                            <input type="text" id="user_name" class="layui-input search" name="user_name" value="" placeholder="名字"/>
                        </div>
                        <div class="layui-input-inline" style="margin-top: 5px">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>

                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.layer_show('新建', '{:url('typeAdd')}')">
                            <i class="fa fa-plus"></i> 添加
                        </button>
                        <button  class="btn btn-danger m-l-xs" href="javascript:;" data-toggle="dropdown">
                            <i class="fa fa-wrench"></i> 批量操作 <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu layui-anim layui-anim-upbit" role="menu">
                           <li><a  href="javascript:;" class="layuiBtn" data-type="excelAll">设置优惠图片</a></li>
                           <li><a  href="javascript:;" class="layuiBtn" data-type="excelAll2">设置优惠文案</a></li>
                           <li><a  href="javascript:;" class="layuiBtn" data-type="excelAll3">设置佣金文案</a></li>
                           <li><a  href="javascript:;" class="layuiBtn" data-type="excelAll4">设置佣金图片</a></li>
                        </ul>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>
                    <!--图片显示模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.t_thumb}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"/>
                    </script>
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.layer_show('编辑/详情', '{:url('typeEdit')}?t_id={{d.t_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑/详情">编辑/详情</a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.t_id}}','{:url('typeDel')}','确定删除吗?')" class="btn btn-danger btn-xs m-r-xs" title="删除">删除</a>
                        <a href="javascript:;" onclick="wk.layer_show('优惠图片', '{:url('imageSet')}?t_id={{d.t_id}}')" class="btn btn-primary btn-xs m-r-xs" title="优惠图片">优惠图片</a>
                        <a href="javascript:;" onclick="wk.layer_show('优惠文案', '{:url('couponSet')}?t_id={{d.t_id}}')" class="btn btn-primary btn-xs m-r-xs" title="优惠文案">优惠文案</a>
                        <a href="javascript:;" onclick="wk.layer_show('佣金文案', '{:url('yongjinSet')}?t_id={{d.t_id}}')" class="btn btn-primary btn-xs m-r-xs" title="佣金文案">佣金文案</a>
                        {{# if(d.t_status == 1) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.t_id}}','{:url('down')}','确定冻结吗?')" class="btn btn-primary btn-xs m-r-xs" title="冻结">冻结</a>
                        {{# } }}
                        {{# if(d.t_status == 2) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.t_id}}','{:url('upup')}','确定解冻吗?')" class="btn btn-warning btn-xs m-r-xs" title="解冻">解冻</a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Types/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 300]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left'},
                  {type:'numbers', width: 70, title: '序号'}
                , {field: 't_id', width: '70', title: 'id', align: 'center'}
                , {field: 't_name', width: '', title: '分类名字', align: 'center'}
                , {field: 't_thumb', width: '', title: '缩略图', align: 'center',templet: '#imgTpl'}
                , {field: 't_remark', width: '', title: '备注', align: 'center'}
                , {field: 't_sort', width: '', title: '排序(可编辑)', align: 'center', edit: 'test'}
                , {field: 't_letter', width: '80', title: '首字母', align: 'center'}
                , {field: 't_time', width: '', title: '发布时间', align: 'center'}
                , {fixed: 'right', width:'400', title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });
        //批量操作
        var $ = layui.$, active = {
            //批量导出订单
            excelAll:function () {
                var ids = getIds();
                if(ids == ''){
                    alert('选择数据不能为空！');
                    return;
                }else{
                    wk.layer_show('设置优惠图片', '{:url('imageSet2')}?t_id=' + ids);
                }

            },
            //批量导出订单
            excelAll2:function () {
                var ids = getIds();
                if(ids == ''){
                    alert('选择数据不能为空！');
                    return;
                }else{
                    wk.layer_show('设置优惠图片', '{:url('couponSet2')}?t_id=' + ids);
                }

            },
            //批量导出订单
            excelAll3:function () {
                var ids = getIds();
                if(ids == ''){
                    alert('选择数据不能为空！');
                    return;
                }else{
                    wk.layer_show('设置优惠图片', '{:url('yongjinSet2')}?t_id=' + ids);
                }

            },
            //批量导出订单
            excelAll4:function () {
                var ids = getIds();
                if(ids == ''){
                    alert('选择数据不能为空！');
                    return;
                }else{
                    wk.layer_show('设置佣金图片', '{:url('yongjinimgSet2')}?t_id=' + ids);
                }

            },
            //全部导出
        };
        //监听单元格编辑---排序
        table.on('edit(testReload)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            wk.change(data.t_id,"{:url('updateSort')}",field,value);
        });
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['t_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>